import React from 'react';
import { FormPro } from '@/components';
import { FormInstance } from 'antd/lib/form';
import { FormItem } from '@/components/FormPro/types';

type Props = { item: any };

class EditContent extends React.PureComponent<Props> {
  componentDidMount() {
    const { item } = this.props;
    if (item) this.form.current?.setFieldsValue?.(item);
  }

  private form = React.createRef<FormInstance>();

  public vailForm = () => {
    return this.form.current?.validateFields();
  }

  render() {
    const formList: FormItem[] = [
      {
        type: 'input',
        name: 'name',
        label: '分类名称',
        rules: [{
          required: true,
          message: '请输入分类名称'
        }]
      },
      {
        type: 'input',
        name: 'regExp',
        label: '分类正则',
        rules: [{
          required: true,
          message: '请输入分类正则'
        }]
      },
      {
        type: 'input',
        name: 'tip',
        label: '上传提示',
        rules: [{
          required: true,
          message: '请输入上传提示'
        }]
      },
      {
        type: 'textArea',
        name: 'describe',
        label: '分类描述',
        rules: [{
          required: true,
          message: '请输入分类描述'
        }]
      }
    ];

    return (
      <FormPro
        ref={this.form}
        formList={formList}
      />
    )
  }
}

export default EditContent;


